<?php

require_once("../config.php");
require_once("../ftp.class.php");

function test_suite_ftp_login()
{
    try {
        $ftp = new ftp(FTPHOST, FTPUSER, FTPPASS);
        $ftp->connect();
        $ftp->close();
        echo "ftp login ssuccessfully.\n";
    } catch (FTPBaseException $e) {
        echo "ftp login failure.\n";
        echo $e->getMessage();
    }
}


function test_suite_ftp_get_current_directory()
{
    try {
        $ftp = new ftp(FTPHOST, FTPUSER, FTPPASS);
        $ftp->connect();
        $directory = $ftp->get_current_directory();
        $ftp->close();
        echo "current directory is '{$directory}'.\n";
    } catch (FTPBaseException $e) {
        echo "ftp get current directory failure.\n";
        echo $e->getMessage();
    }
}


function test_suite_ftp_change_directory1()
{
    try {
        $ftp = new ftp(FTPHOST, FTPUSER, FTPPASS);
        $ftp->connect();
        $ftp->change_directory("bb/cc");
        $directory = $ftp->get_current_directory();
        $ftp->close();
        echo "current directory is '{$directory}'.\n";
    } catch (FTPBaseException $e) {
        echo "ftp get current directory failure.\n";
        echo $e->getMessage();
    }
}


function test_suite_ftp_change_directory2()
{
    try {
        $ftp = new ftp(FTPHOST, FTPUSER, FTPPASS);
        $ftp->connect();
        $ftp->change_directory("/bb/");
        $directory = $ftp->get_current_directory();
        $ftp->close();
        echo "current directory is '{$directory}'.\n";
    } catch (FTPBaseException $e) {
        echo "ftp get current directory failure.\n";
        echo $e->getMessage();
    }
}


function test_suite_ftp_create_directory1()
{
    try {
        $ftp = new ftp(FTPHOST, FTPUSER, FTPPASS);
        $ftp->connect();
        $ftp->create_directory("/1/2/3");
        $ftp->close();
        echo "create directory successfully.\n";
    } catch (FTPArgumentsException $e) {
        echo "ftp create directory failure. argument exception\n";
        echo $e->getMessage();
    } catch (FTPOperationFailureException $e) {
        echo "ftp create directory failure. operation failure exception\n";
        echo $e->getMessage();
    }
}


function test_suite_ftp_create_directory2()
{
    try {
        $ftp = new ftp(FTPHOST, FTPUSER, FTPPASS);
        $ftp->connect();
        $ftp->create_directory("/4/5/6");
        $ftp->close();
        echo "create directory successfully.\n";
    } catch (FTPArgumentsException $e) {
        echo "ftp create directory failure. argument exception\n";
        echo $e->getMessage();
    } catch (FTPOperationFailureException $e) {
        echo "ftp create directory failure. operation failure exception\n";
        echo $e->getMessage();
    }
}


function test_suite_ftp_create_directories()
{
    try {
        $directories = array("5/7/9", "/4/35/36");
        $ftp = new ftp(FTPHOST, FTPUSER, FTPPASS);
        $ftp->connect();
        $ftp->change_directory("/mm");
        $ftp->create_directories($directories);
        $ftp->close();
        echo "create directory successfully.\n";
    } catch (FTPArgumentsException $e) {
        echo "ftp create directories failure. argument exception\n";
        echo $e->getMessage();
    } catch (FTPOperationFailureException $e) {
        echo "ftp create directories failure. operation failure exception\n";
        echo $e->getMessage();
    }
}


function test_suite_ftp_list_files()
{
    try {
        $ftp = new ftp(FTPHOST, FTPUSER, FTPPASS);
        $ftp->connect();
        $ftp->change_directory("/");
        $files = $ftp->list_file('/4', true);
        $ftp->close();
        var_dump($files);
        echo "create directory successfully.\n";
    } catch (FTPArgumentsException $e) {
        echo "ftp lsit file failure. argument exception\n";
        echo $e->getMessage();
    } catch (FTPOperationFailureException $e) {
        echo "ftp list file failure. operation failure exception";
    }
}


function test_suite_ftp_upload_file()
{
    try {
        $ftp = new ftp(FTPHOST, FTPUSER, FTPPASS);
        $ftp->connect();
        $ftp->upload("/home/Jobs/SortExamples/BubbleSort.d/BinaryBubblesort", "/BinaryBubblesort");
        $ftp->close();
        echo "upload file success.\n";
    } catch (FTPargumentsException $e) {
        echo "ftp upload file failure. argument exception\n";
        echo $e->getMessage();
    } catch (FTPOperationFailureException $e) {
        echo "ftp upload file failure. Operation failure exception\n";
        echo $e->getMessage();
    } catch (FTPUploadException $e) {
        echo "ftp upload file failure\n";
        echo $e->getMessage();
    }
}


function test_suite_ftp_download_file()
{
    try {
        $ftp = new ftp(FTPHOST, FTPUSER, FTPPASS);
        $ftp->connect();
        $ftp->download("/BinaryBubblesort", "/tmp/BinaryBubblesort");
        $ftp->close();
        echo "download file success\n";
    } catch (FTPArgumentsException $e) {
        echo "ftp download file failure. argument exception\n";
        echo $e->getMessage();
    } catch (FTPOperationFailureException $e) {
        echo "ftp download file failure. Operation failure exception\n";
        echo $e->getMessage();
    } catch (FTPDownloadException $e) {
        echo "ftp download file failire\n";
        echo $e->getMessage();
    }
}


function test_suite_ftp_remove_file()
{
    try {
        $ftp = new ftp(FTPHOST, FTPUSER, FTPPASS);
        $ftp->connect();
        $ftp->remove_file("/BinaryBubblesort");
        $ftp->close();
        echo "success file success\n";
    } catch (FTPArgumentsException $e) {
        echo "ftp remove file failure. argument exception\n";
        echo $e->getMessage();
    } catch (FTPOperationFailureException $e) {
        echo "ftp remove file failure. Operation failure exception\n";
        echo $e->getMessage();
    }
}


function test_suite_ftp_remove_dir()
{
    try {
        $ftp = new ftp(FTPHOST, FTPUSER, FTPPASS);
        $ftp->connect();
        $ftp->remove_dir("/4");
        $ftp->close();
        echo "remove directory success\n";
    } catch (FTPArgumentsException $e) {
        echo "ftp remove directory failure. argument exception\n";
        echo $e->getMessage();
    } catch (FTPOperationFailureException $e) {
        echo "ftp remove directory failure. Operation failure exception\n";
        echo $e->getMessage();
    }
}


function test_suite_ftp_chmod()
{

    try {
        $ftp = new ftp(FTPHOST, FTPUSER, FTPPASS);
        $ftp->connect();
        $ftp->chmod("/mm", 0660);
        $ftp->close();
    } catch (FtpArgumentsException $e) {
        echo "ftp chmod file failure. argument exception";
        echo $e->getMessage();
    }

} 
